package com.lynn.springboot_demo.controller;

import com.lynn.springboot_demo.model.User;
import com.lynn.springboot_demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

/**
 * @author cl
 * @Date 2020/5/21 11:32
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 直接用对象来接收参数，须使用@RequestBody注解
     * @param user
     */
    @PostMapping("/insert")
    public void insert(@RequestBody User user) {
        userService.insert(user);
    }

    @PostMapping("/delete")
    public void delete(int id){
        userService.delete(id);
    }

    @GetMapping("/getUser")
    public User getUser(String name){
        return userService.findByName(name);
    }


}
